package com.badibadi.adapter;

import java.util.ArrayList;
import java.util.List;

import com.android.volley.toolbox.NetworkImageView;
import com.badibadi.infos.Article_img_Model;
import com.badibadi.infos.BrowseAllPhoto_Model;
import com.badibadi.infos.Record_Info_Model;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.VolleyTools;
import com.badibadi.uniclubber.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.R.integer;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class LogReadingPictureAdapter extends BaseAdapter{

	List<Article_img_Model> mlist;
	Context context;
	
	private DisplayImageOptions options;
	public LogReadingPictureAdapter(Context context,List<Article_img_Model> list)
	{
		this.context=context;
		mlist=list;
		options = new DisplayImageOptions.Builder()
		.showStubImage(R.drawable.ic_stub)
		.showImageForEmptyUri(R.drawable.noimage)
		.showImageOnFail(R.drawable.noimage).cacheInMemory()
		.cacheOnDisc().displayer(new RoundedBitmapDisplayer(0)).build();
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mlist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		
		
		return mlist.get(position);
	}

	/**
	 * @return
	 */
	public List<BrowseAllPhoto_Model> getItemToBrowseAll()
	{
		List<BrowseAllPhoto_Model> l=new ArrayList<BrowseAllPhoto_Model>();//=(List<BrowseAllPhoto_Model>) ob
	    for(int i=0;i<mlist.size();i++)
	    {
	    	BrowseAllPhoto_Model br=new BrowseAllPhoto_Model();
	    	br.setId(mlist.get(i).getId());
	    	br.setPath(mlist.get(i).getPath());
	    	
	    	l.add(br);
	    }
		return l;
		
	}
	
	
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater inflater=LayoutInflater.from(context);
		ViewHolder holder=new ViewHolder();
		if(convertView==null)
		{
			convertView=inflater.inflate(R.layout.net_img1_img, null);
			holder.img=(ImageView)convertView.findViewById(R.id.img);
			convertView.setTag(holder);
		}
		else
		{
			holder=(ViewHolder) convertView.getTag();
		}
		try {
			ImageLoader.getInstance().displayImage(Constants.BadiDownImgUrl+"/"+mlist.get(position).getPath()+Constants.App9block, holder.img, options);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
//		try {
//			VolleyTools.displayImageByNetworkImageView(context, Constants.BadiDownImgUrl+"/"+mlist.get(position).getPath()+Constants.Appactivitycover, holder.img);
//		} catch (Exception e) {
//			// TODO: handle exception
//		}
	
		return convertView;
	}

	static class ViewHolder{
		ImageView img;
	}
}
